<?php header('Content-type: application/x-javascript'); ?>
var xPathData = {};
<?php
function base64url_decode($base64url) {
	$base64 = strtr($base64url, '-_', '+/');
	$plainText = base64_decode($base64);
	return ($plainText);
}
function base64url_encode($plainText) {
	$base64 = base64_encode($plainText);
	$base64url = strtr($base64, '+/', '-_');
	return ($base64url);   
}
$urlPath = $_GET['path'];
$ignorevals = array ("Icon","Icon\x0D" ,"index.php", "TheVolumeSettingsFolder");
$folderPath = base64url_decode($urlPath);

$dir_handle = @opendir($folderPath) or die("Musiker.modBrowser.artistsByName[0] = 'Unable to open $remdir';");
while ($file = readdir($dir_handle)) {
	$key = strtoupper($file);
	if (substr($key,0,4)=='THE ') $key = substr($key,4);
	while (isset($files[$key])) $key = $key.'_';				//Eliminate cases of "Beach Boys" overwriting "The Beach Boys"

	if ($file{0} != '.' && !in_array($file,$ignorevals)) $files[$key] = $file;
	
}
ksort($files, SORT_STRING);
closedir($dir_handle);

foreach ($files as $stritem) {
	$outdir = "$folderPath/$stritem";	
	$getdir = base64url_encode($outdir);
	
	echo "	xPathData['", htmlentities($stritem,ENT_QUOTES), "'] = '$getdir';\n";
}

echo "Musiker.modBrowser.pathContent['$urlPath'] = xPathData;\n";

if (isset($_GET['output'])) echo "Musiker.modBrowser.loadSubFolder('$urlPath','", $_GET['output'] ,"')\n";
?>

